home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 025 (1987-08-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 025 (1987-08-15)(Ossowski, Stefan)(DE)(PD).adf / Bastelei / jtime.txt < prev    next >
Text File  |  1987-03-08  |  9KB  |  200 lines

  1. TITLE: JTime: A Real-Time Clock for the Amiga
  2.                JTime: A Real-Time Clock for the Amiga
  3.                          By Michael Keryan
  4.  
  5. Introduction
  6.  
  7. The Amiga computer automatically puts a date and time stamp
  8. on all your files.  This feature is extremely helpful when
  9. searching for files.  For example, you can examine statistics
  10. on all recently created files in the current directory
  11. with a DOS command such as LIST SINCE SATURDAY.  However,
  12. for these dates to be meaningful, you must set the time and
  13. date every time you boot up the system.  If you boot into
  14. the icon-controlled Workbench environment, you would double-
  15. click the Preferences icon, then adjust the time and date
  16. gadgets.  If you boot into the text oriented Command Line
  17. Interface (CLI), you most likely would set the time and date
  18. with the AmigaDOS command DATE.  Either way, it doesn't take
  19. very long to get tired of setting the date.
  20.   Several third-party firms offer battery backed-up real-time
  21. clocks for the Amiga computer.  Some of these connect to the
  22. parallel port and provide another connector for a parallel
  23. printer.  Although these are advertised to be transparent to
  24. printer operation, Amiga newsletters and bulletin boards
  25. indicate a possible contention problem.
  26.   A second type of connection is similar to clocks used on the
  27. IBM PC, on a board connected to the bus system.  However, the
  28. bus on the Amiga is accessible only through the 86-pin
  29. connector on the side of the computer.  Most firms provide
  30. this type of interfacing only in conjunction with external RAM
  31. or multifunction boards.  Most Amiga owners haven't yet taken
  32. the plunge into the world of two-megabyte ram boards or SCSI
  33. disk drives.
  34.   The third type of real-time clock interfacing on the Amiga
  35. is through the #2 game port connector.  This connector is
  36. directly behind the mouse cable connector.  It is used only
  37. for joystick-type games.  Because the clocks contain their
  38. own battery, they continue to work if unplugged from the
  39. computer so that the joystick can be plugged in.  This type
  40. of connection is preferred over the others.  The external
  41. connection allows easy battery replacement.  The port is
  42. rarely used for anything else; even when it is used for a
  43. joystick, there are no contention problems since the clock
  44. must be physically removed to plug in the joystick.
  45.   In this article, I describe a method to connect a real-time
  46. clock to the Amiga through the #2 joyport, and provide
  47. software to read and set the clock.  The software can be
  48. installed on your boot disk so that the date and time are
  49. automatically set every time you turn on the machine.
  50.  
  51.  
  52. TITLE: The Clock Chip
  53.  
  54. The JTime circuit uses an inexpensive, easy-to-get, state-of-
  55. the-art clock module, the RTC 58321 by SaRonix.  This circuit
  56. contains just about everything a computer needs for a
  57. clock:  a complete clock/calendar with leap-year correction,
  58. a 4-bit bidirectional data bus, and a built-in factory
  59. trimmed and sealed quartz crystal, all in one 16-pin IC
  60. package.  The clock circuit requires only about 10 to 20
  61. microamps at 3 to 5 volts to operate.
  62.   The RTC 58321 contains sixteen 4-bit wide registers, most
  63. of which contain the time and date information and can be
  64. written to and read like standard static RAM memory.  The
  65. registers are selected by sending to the chip an address
  66. through the 4-bit bus while pulsing the Address Write line.
  67. After selecting the address, you can read the contents of
  68. that register by pulsing the Read line and reading the data
  69. on the 4-bit bus.  To set the clock, select an address as
  70. above, then pulse the Write line while sending the clock
  71. chip the data over the 4-bit bus.  The internal registers
  72. hold BCD representations of all time and date counters such
  73. as units of seconds, tens of seconds,... tens of years.
  74.  
  75.  
  76. TITLE: The Circuit
  77.  
  78. The Amiga's #2 game port has available seven I/O lines, but
  79. only two of these are general-purpose I/O; the others are
  80. used for input only through the Amiga's ROM routines.  Four
  81. of these lines (normally used for joystick up/down/left/
  82. right inputs) can be used to read clock data.  However,
  83. additional circuitry is required to send data to the four
  84. data lines and four control lines on the clock module over
  85. only two lines.
  86.   The circuit I came up with is in Figure 1, and the timing
  87. diagrams are shown in Figure 2.  (See the discussion on
  88. jtime.arc below.) One of the two output bits (from the
  89. computer) is used to pulse a counter. The other bit is used to
  90. release this count to the clock's data and control lines, to
  91. trigger either an Address Write cycle, a data Write cycle, or
  92. a data Read cycle.
  93.   The computer sends pulses to IC1, wired as an 8-bit binary
  94. counter.  The lower 4 bits represent the BCD data to the
  95. clock registers; the upper 4 bits (of which only 3 are
  96. actually used) control the Address Write, Read, and Write
  97. lines.  Trace A of Figure 2 shows that this count data is
  98. loaded before anything else occurs.  As shown in trace B,
  99. the data from the counter is stable until the counter is
  100. reset.  After the count is loaded, the other data bit is
  101. pulsed high for a certain period as shown in trace C.  A
  102. half-monostable circuit (trace D) creates a counter reset
  103. pulse at the end of this chip-select period (trace E).
  104.   As shown in traces F and G, the chip select signal is
  105. delayed to create a signal to enable a Read pulse.  The bit
  106. indicating a Read cycle (pin 14 of IC3) is inverted so that
  107. the Read cycles shut off the bidirectional switches in IC2
  108. to allow the 4-bit data being sent to the Amiga to consist of
  109. data from the clock, not data from the counter.  Per trace
  110. H, a fairly wide window is available to allow the computer
  111. sufficient time to read valid data.
  112.   The Address Write and data Write cycles operate in a very
  113. similar manner.  A half-monostable is used to generate a
  114. pulse (traces I and J) that enables either an Address Write
  115. or a Write pulse through bidirectional switch IC3.  An AD WR
  116. cycle occurs when the counter bit Q4 is high, while a data
  117. WRITE cycle is triggered by a high level on Q6.  Obviously,
  118. the software must not allow more than one of any of the
  119. three control lines to be active at the same time.
  120.  
  121.  
  122. TITLE: Required Programs
  123.  
  124. Programs are required to read the real-time clock and set the
  125. Amiga clock automatically each time the computer is turned on
  126. and to read the Amiga clock and set the real time clock twice
  127. a year during time changes (and if a battery has drained and
  128. requires replacement). The programs could be written in any
  129. language, but assembly or stand-alone executable code from a
  130. compiler (such as C, Modula 2, FORTRAN, etc.) is desired.  To
  131. read the clock, run the program from CLI with no other
  132. parameters on the command line:  JTIME.  To set the clock, use
  133. a parameter "1" following the command:  JTIME 1.
  134.  
  135.   Data is passed to and from the JTime program through RAM-
  136. based files:  RAM:TIMEIN and RAM:TIMEOUT.  When the clock is
  137. read, the file TIMEOUT is created and written to RAM:.  It
  138. consists of one line of data, the letters "DATE" followed
  139. by the date and time in AmigaDOS format.  This RAM: file is
  140. then Executed as an AmigaDOS command which then sets the
  141. time and date in the computer.  The following can be
  142. inserted into your S/Startup-Sequence file on the Workbench
  143. disk you normally use to boot up the system:
  144.  
  145.   JTime
  146.   Execute RAM:TIMEOUT
  147.   Delete RAM:TIMEOUT
  148.  
  149. After the initial setting of the real-time clock, the date
  150. and time only have to be set twice a year for time changes,
  151. and if the battery needs replaced.  Actually, the battery
  152. can be changed while the computer is on without losing time
  153. since 5 volts from the Amiga is provided through diode D2.
  154. To set the clock, first set the time and date in the
  155. computer with either the DATE command in the CLI, with
  156. Preferences, or with other time-setting programs such as the
  157. public-domain program TimeSet.  Then enter a command to copy
  158. the current date and time to a RAM: file called TIMEIN.
  159. Lastly, run the JTime program with a "1" on the command
  160. line.  This can all be done with a program called SET that
  161. you can place in the S directory of your Workbench boot
  162. disk.  To set the clock type in:  EXECUTE SET.  This program
  163. follows:
  164.  
  165.   Date?              (this prompts you to type in date&time)
  166.   Date > RAM:TIMEIN
  167.   JTime 1
  168.   Delete RAM:TIMEIN
  169.  
  170.  
  171. TITLE: Building the Clock
  172.  
  173. You can buy all the parts for the circuit for less than $25;
  174. see the parts list (see the discussion on jtime.arc below). A
  175. good source for all parts was found to be Jameco Electronics,
  176. 1355 Shoreway Road, Belmont CA 94002. Jameco sells the real-
  177. time clock module IC for $7.95.
  178.   The prototype was wired point-to-point on a small board and
  179. placed in a small plastic box.  The battery is held snug
  180. with small strips of Velcro.  A 3-foot 9-conductor cable
  181. connects the clock circuitry to the computer, allowing you
  182. to locate the clock in a convenient location.
  183.   An inexpensive 9-volt battery was used in place of the
  184. relatively hard to find 3-volt lithium batteries you
  185. normally see used with this type of circuit.  Due to the low
  186. power drain, the battery should last to nearly its shelf
  187. life.
  188.   Unfortunately, no etched PC board is available at this
  189. time.  Maybe your users' group can set up a project to make
  190. up boards for all the members.
  191.  
  192. ======== new Startup-Sequence file==========
  193. JTime
  194. Execute RAM:TIMEOUT
  195. Delete ram:TIMEOUT
  196. Date > LastDate
  197. LoadWB
  198. Quit
  199.  
  200.